]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
powerProfiles: Handle error if profile does not exists
authorMorgan <me@morgan.kr>
Wed, 25 Jun 2025 12:52:02 +0000 (21:52 +0900)
committerMorgan <me@morgan.kr>
Wed, 25 Jun 2025 13:53:35 +0000 (22:53 +0900)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3774>

js/ui/status/powerProfiles.js

index 21680207ddaf15c2f03c925ad11ad0527db53b37..3145c23751f8729756cb5e502e21ebdaa4fad3f6 100644 (file)
@@ -31,6 +31,11 @@ const PROFILE_PARAMS = {
     },
 };
 
+const FALLBACK_PARAMS = {
+    name: C_('Power profile', 'Custom'),
+    iconName: 'gnome-power-manager-symbolic',
+};
+
 const LAST_PROFILE_KEY = 'last-selected-power-profile';
 
 const PowerProfilesToggle = GObject.registerClass(
@@ -82,6 +87,9 @@ class PowerProfilesToggle extends QuickMenuToggle {
             .map(p => p.Profile.unpack())
             .reverse();
         for (const profile of profiles) {
+            if (!PROFILE_PARAMS[profile])
+                continue;
+
             const {name, iconName} = PROFILE_PARAMS[profile];
             if (!name)
                 continue;
@@ -110,7 +118,7 @@ class PowerProfilesToggle extends QuickMenuToggle {
                 : PopupMenu.Ornament.NONE);
         }
 
-        const {name: subtitle, iconName} = PROFILE_PARAMS[activeProfile];
+        const {name: subtitle, iconName} = PROFILE_PARAMS[activeProfile] ?? FALLBACK_PARAMS;
         this.set({subtitle, iconName});
 
         this.checked = activeProfile !== 'balanced';